home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Inside!
/
Amiga FD Inside (1995)(Ultramax).iso
/
amigagadget
/
ausgabe13
/
texte
/
prg.non_rectangular_images
< prev
next >
Wrap
Text File
|
1995-02-23
|
3KB
|
79 lines
#Titel DrawImage & non-rectangular Image
#Logo pinsel/ag.prog
#C32
#Font Frankfurter 16
DrawImage & non-rectangular Image
#Font topaz 8
#C21
People frequently ask how to use DrawImage to put a non-rectangular Image into
a RastPort. The answer is "You can't". There is, of course, a way to put
non-rectangular image data into a RastPort which is only slightly more
difficult than using DrawImage. Instead of storing your data as an Image you
must store it as a BitMap. This is because you must draw the image with
BltMaskBitMapRastPort. The method for drawing an image with an arbitrary
transparent color into a RastPort is explained below:
For a BitMap, the actual image data is stored the same as for an Image. The
BitMap structure is constructed like this (Assuming the image data is in an
array called "Buffer"):
#C10
PlaneBytes = RASSIZE(ImageWidth, ImageHeight);
BM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR);
InitBitMap(BM, ImageDepth, ImageWidth, ImageHeight);
for (i = 0; i < ImageDepth; i++)
BM->Planes[i] = &Buffer[PlaneBytes * i];
#C21
The construction of the mask is the next step. The Mask is just a bit plane
with the same dimensions as the image bitplanes. The blitter routines require
the use of BitMaps so we construct two temporary BitMap structures. MaskBM is
the BitMap for the Mask. TempBM is the BitMap which will contain successively
each plane of the image data. The third from the last parameter in the
BltBitMap calls is the "minterm". 0xb0 causes BltBitMap to set all bits in
MaskBM which are not set in TempBM (In addition to those already set in
MaskBM). 0xe0 causes BltBitMap to set all bits in MaskBM which are set in
TempBM (In addition to those already set in MaskBM).
#C10
Mask = AllocRaster(ImageWidth, ImageHeight);
BltClear(Mask, PlaneBytes, 1);
MaskBM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR));
InitBitMap(MaskBM, 1, ImageWidth, ImageHeight);
MaskBM->Planes[0] = Mask;
TempBM = (struct BitMap *)AllocMem(sizeof(struct BitMap), MEMF_CLEAR));
InitBitMap(TempBM, 1, ImageWidth, ImageHeight);
for (i = 0; i < ImageDepth; i++)
{
TempBM->Planes[0] = &Buffer[PlaneBytes * i];
if (TransparentColor & (1<<i))
BltBitMap(TempBM, 0, 0, MaskBM, 0, 0, ImageWidth, ImageHeight, 0xb0,
0xff, NULL);
else
BltBitMap(TempBM, 0, 0, MaskBM, 0, 0, ImageWidth, ImageHeight, 0xe0,
0xff, NULL);
}
FreeMem(TempBM, sizeof(struct BitMap));
FreeMem(MaskBM, sizeof(struct BitMap));
#C21
This code allows for a general transparent color which need not be color zero.
The "if" statement could be removed if the transparent color was always 0.
#Seitenende
To place this image at a point "X, Y" in the window "Window" you only need to
make the following call.
#C10
BltMaskBitMapRastPort(BM, 0, 0, Window->RPort, X, Y, ImageWidth,
ImageHeight, 0xe0, Mask);
#C21
There! Now, wasn't that simple. Of course, in any real program it would be a
good idea to check the return values of all routines which allocate memory.
#C31
by Mike Stark
#C21